package com.project.controller;

import com.project.bean.ClassBean;
import com.project.bean.CutPageBean;
import com.project.bean.RoomBean;
import com.project.bean.StudentBean;
import com.project.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("student")
public class StudentController {
    @Autowired
    private IStudentService studentService;

    @RequestMapping("findByItem")
    public CutPageBean<StudentBean> findByItem(Integer pageNO, String name, String className, String address) {

        return studentService.findByItem(pageNO, name, className, address);
    }

    @RequestMapping("del")
    public String del(Integer id) {
        studentService.del(id);
        return "ok";
    }

    @RequestMapping("update")
    public String update(Integer id, Integer roomId) {
        studentService.update(id, roomId);
        return "ok";
    }

    @RequestMapping("add")
    public String add(StudentBean studentBean, Integer classId, Integer roomId) {

        ClassBean classBean = new ClassBean();
        classBean.setId(classId);
        studentBean.setClassBean(classBean);
        RoomBean roomBean = new RoomBean();
        roomBean.setId(roomId);
        studentBean.setRoomBean(roomBean);
        studentService.add(studentBean);

        System.out.println(studentBean);

        return "ok";
    }

    @RequestMapping("findById")
    public StudentBean findById(Integer id) {

        System.out.println(studentService.findById(id));
        return studentService.findById(id);
    }


}
